import JoyStick, { IJoyStickType } from "./JoyStick";
import { JoyStickTypeBase } from "./TypeBase";

export default class JoyStickTypeFollow extends JoyStickTypeBase implements IJoyStickType {
    constructor(stick: JoyStick) {
        super(stick)
    }
    touchStartEvent(event: cc.Event.EventTouch): boolean {
        const touchPos = this._stick.node.convertToNodeSpaceAR(event.getLocation())
        this._stick._stickPos = touchPos
        this._stick.show.active = true
        this._stick._touchLocation = event.getLocation()

        this._stick.ring.setPosition(touchPos)
        this._stick.dot.setPosition(touchPos)
        return true
    }
    touchMoveEvent(event: cc.Event.EventTouch): boolean {
        if (this._stick._touchLocation === event.getLocation()) {
            return false
        }
        return true
    }
    touchEndEvent(event: cc.Event.EventTouch): boolean {
        this._stick.show.active = false
        return true
    }
    init() {
        this._stick.show.active = false
    }
}
